//filtrable tree panel - based on ext.panel and ext.tree.treepanel
//TrueOrFalse.Yuan
//2009.3.24
FiltertTreePanel = function(cfg,panelcfg,treepanelcfg) {
	this.config = {
		id:'',
		title:'&nbsp;',
		url:''
	};
	Ext.apply(this.config, cfg||{});
	
	this.treepanelconfig = {
		autoScroll :false,
		collapsible :false,
		containerScroll :false,
		rootVisible :false,
		bodyBorder :false,
		lines :false
	};
	Ext.apply(this.treepanelconfig, treepanelcfg||{});
	Ext.apply(this.treepanelconfig, {
		loader :new Ext.tree.TreeLoader( {
			dataUrl : this.config.url
		}),
		root :new Ext.tree.AsyncTreeNode( {
			text :this.config.title
		})
	});

	if(this.config.id != ''){
		Ext.apply(this.treepanelconfig, {id: 'ftp-tp-' + this.config.id});
	}

	
	this.treepanel = new Ext.tree.TreePanel(this.treepanelconfig);
	this.panelconfig = {
		title :'&nbsp;',
			items :this.treepanel,
			tbar : [ {
				text :'Filter:'
			}, {
				xtype :'textfield',
				id :'filter',
				selectOnFocus :true,
				width :100
			}, {
				text :'Search',
				handler :doSearch
			} ],
			autoScroll :true,
			collapsible :true
		};
	Ext.apply(this.panelconfig, panelcfg||{});


	if(this.config.id != ''){
		Ext.apply(this.panelconfig, {id: 'ftp-' + this.config.id});
	}
	if(this.config.title != '&nbsp;' && this.panelconfig.title == '&nbsp;'){
		Ext.apply(this.panelconfig, {title:this.config.title});
	}
	FiltertTreePanel.superclass.constructor.call(this, this.panelconfig);
}

Ext.extend(FiltertTreePanel, Ext.Panel, {});

function doSearch() {
	alert("Search Clicked!!");
	var loader = sidebar_tree.getLoader();
	sidebar_tree.on('beforeload', function() {
		loader.dataUrl = loader.dataUrl;
		loader.baseParams = {
			test :"test-string"
		};
	});
	sidebar_tree.getRootNode().reload();
}